import { createApp } from "vue";
import Message from "@/components/Message.vue";
type MessageType = "default" | "error" | "success";
const createMessage = (message: string, type: MessageType, timeout = 2000) => {
  console.log("message", Message);
  // 第一个参数，Message为组件的选项对象；第二个参数 为传递给组件props
  const messageInstance = createApp(Message, {
    message,
    type,
  });
  const mountNode = document.createElement("div");
  document.body.appendChild(mountNode);
  /* 将vue实例挂载在节点mountNode上 */
  messageInstance.mount(mountNode);
  // 异步，页面渲染
  setTimeout(() => {
    messageInstance.unmount();
    document.body.removeChild(mountNode);
  }, timeout);
};
export default createMessage;
